﻿using System.Collections.Generic;
using PEProtocol;
using UnityEngine;

public class AcctSystem : ILogic
{
    private PERoot mRoot;
    private EvtSvc mEvtSvc;
    private NetSvc mNetSvc;
    public string Account;
    private List<RoleData> mRoleDatas;

    public string IP { get; set; }
    public int Port { get; set; }
    public string Token { get; set; }
    public int SelectUID { get; set; }


    public List<RoleData> RoleDatas
    {
        get { return mRoleDatas; }
        set
        {
            mRoleDatas = value;
            mEvtSvc.InvokeMsgHandler(EvtID.OnRoleDataUpdate, mRoleDatas);
        }
    }

    public void Init()
    {
        mRoot = PERoot.Instance;
        mEvtSvc = mRoot.EvtService;
        mNetSvc = mRoot.NetService;
        System.Random random = new System.Random();
        int num = random.Next(999, 9999);
        Account = $"雨泽_{num}";

        this.Log("AcctSystem Init...");
        mNetSvc.AddMsgHandle(CMD.NtfRoleDatas, NtfRoleDatas);
    }

    public void Tick()
    {
      
    }

    public void NtfRoleDatas(NetMsg msg)
    {
        RoleDatas = msg.NtfRoleDatas.RoleDatas;
    }

    public void UnInit()
    {
        this.Log("AcctSystem UnInit...");
    }
}